找传奇、传世资源到传世资源站!

Qt调用摄像头拍照(截图)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboard from clipboard
#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow){ ui->setupUi(this); camera = new QCamera(this); //viewfinder = new QCameraViewfinder(this); m_view = new MyView(this); imageCapture = new QCameraImageCapture(camera); //ui->ImageView->addWidget(viewfinder); ui->ImageView->addWidget(m_view); ui->ImageCapture->setScaledContents(true); //camera->setViewfinder(viewfinder); camera->setViewfinder(m_view); connect(imageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(displayImage(int,QImage))); connect(ui->buttonCapture, SIGNAL(clicked()), this, SLOT(captureImage())); connect(ui->buttonSave, SIGNAL(clicked()), this, SLOT(saveImage())); connect(ui->buttonQuit, SIGNAL(clicked()), qApp, SLOT(quit())); connect(ui->buttonStop,SIGNAL(clicked()),camera,SLOT(stop())); connect(ui->buttonStart,SIGNAL(clicked()),camera,SLOT(start()));}MainWindow::~MainWindow(){ delete ui;}void MainWindow::captureImage(){ imageCapture->capture();}void MainWindow::displayImage(int , QImage image){ QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); image.save(&buffer,"jpg"); ui->ImageCapture->setText(QString::number(ba.size())); QImage pic; pic.loadFromData(ba); ui->ImageCapture->setPixmap(QPixmap::fromImage(pic));}void MainWindow::saveImage(){ QString fileName=QFileDialog::getSaveFileName(this, tr("save file"), QDir::homePath(), tr("jpegfile(*.jpg)")); if(fileName.isEmpty()) { return; } const QPixmap* pixmap=ui->ImageCapture->pixmap(); if(pixmap) { pixmap->save(fileName); }}

【源码目录】.
└── untitled
    ├── main.cpp
    ├── mainwindow.cpp
    ├── mainwindow.h
    ├── mainwindow.ui
    ├── myview.cpp
    ├── myview.h
    ├── untitled.pro
    ├── untitled.pro.user
    ├── untitled.pro.user.22
    └── untitled.pro.user.b66346c

1 directory, 10 files

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复